package com.zby.ss.core.builder;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created By zby on 20:21 2019/2/16
 * 创建类字面常量
 */

public class ClassBuilder<T> {

    private static Logger logger = LoggerFactory.getLogger(ClassBuilder.class);

    /**
     * Created By zby on 20:19 2019/2/16
     * 通过类路径转为类字面常量
     *
     * @param classPath 类路径
     */
    public static <T> Class<T> classPathToClazz(String classPath) {
        if (StringUtils.isBlank(classPath)) {
            throw new RuntimeException("类路径不存在");
        }
        try {
            return (Class<T>) Class.forName(classPath);
        } catch (ClassNotFoundException e) {
            logger.error("路径" + classPath + "不存在,创建失败e=" + e);
            e.printStackTrace();
        }
        return null;
    }

}
